﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Enums;
using Silvermoon.Controls.Interfaces;

namespace Silvermoon
{
    public abstract class Transformation
    {
        /// <summary>
        /// Identifies what Transformation type this is. This method is uses, since it is significantly faster than using casting in the way of (if t is AnyAnimation).
        /// </summary>
        public abstract TransformationId Id { get; }
    }

    namespace Enums
    {
        public enum TransformationId
        {
            Unknown = 0,
            Rotate = 1,
            Translate = 2,
            Scale = 3,
            Transparent = 4,
            Zoom = 5
        }
    }

    public class RotateTransform : Transformation
    {
        public float Angle { get; set; }
        public RotateAxis Axis { get; set; }

        public static readonly float Degree90 = 90F;
        public static readonly float Degree180 = 180F;
        public static readonly float Degree270 = 270F;
        public static readonly float Degree0 = 0F;

        public override TransformationId Id { get { return TransformationId.Rotate; } }
    }

    public enum RotateAxis
    {
        XAxis,
        YAxis,
        ZAxis
    }

    /// <summary>
    /// Scales from the center.
    /// </summary>
    public class ScaleTransform : Transformation, IScaleTransform
    {
        public float X { get; set; }
        public float Y { get; set; }
        public float Z { get; set; }

        public ScaleTransform()
            : base()
        {
            X = Y = Z = 1f;
        }

        public ScaleTransform(float scaleX, float scaleY, float scaleZ)
        {
            X = scaleX;
            Y = scaleY;
            Z = scaleZ;
        }

        public override TransformationId Id { get { return TransformationId.Scale; } }
    }

    /// <summary>
    /// Scales from top left.
    /// </summary>
    public class StretchTransform : Transformation, IScaleTransform
    {
        public float X { get; set; }
        public float Y { get; set; }
        public float Z { get; set; }

        public StretchTransform()
            : base()
        {
            X = Y = Z = 1f;
        }

        public StretchTransform(float scaleX, float scaleY, float scaleZ)
        {
            X = scaleX;
            Y = scaleY;
            Z = scaleZ;
        }

        public override TransformationId Id { get { return TransformationId.Zoom; } }
    }

    public class TranslateTransform : Transformation
    {
        public float OffsetX { get; set; }
        public float OffsetY { get; set; }
        public float OffsetZ { get; set; }

        public override TransformationId Id { get { return TransformationId.Translate; } }

    }

    public class TransparentTransform : Transformation
    {
        private int alpha = 0;

        public int Alpha { get { return alpha; } set { value = CheckRange(value); alpha = value; } }

        private int CheckRange(int value)
        {
            if (value < 0) return 0;
            if (value > 255) return 255;
            return value;
        }

        public override TransformationId Id { get { return TransformationId.Transparent; } }


    }
}


